package leetcode.秋招.百度;

import java.util.Scanner;

/**
 * @author ：zsy
 * @date ：Created 2021/9/7 19:57
 * @description：
 */
public class Main1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            String num = in.next();
            char[] chars = (num + "").toCharArray();
            StringBuilder builder = new StringBuilder();
            for (int j = 0; j < chars.length; j++) {
                builder.append('3');
            }
            while (num.compareTo(builder.toString()) < 0) {
                char c = builder.charAt(0);
                if (c != 0) {
                    builder.replace(0, 1, String.valueOf(c - 1));
                }
                builder.deleteCharAt(0);
            }
            if (builder.charAt(0) == '0') {
                System.out.println(builder.substring(1));
            } else
                System.out.println(builder);
        }
    }
}
